/*
* Copyright (C) 2011 Uni Osnabrück
*
* This file is part of the LSSR-Toolkit,
*
* LSSR is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LSSR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA

*/
/**
*	AsteroidField.cpp
*
* @date	  16.12.2012 
* @author Carlos Engelfried (cengelfr@uos.de)
* @author Clemens John (cjohn@uos.de)
*/
#include "AsteroidField.hpp"

namespace asteroids
{
	AsteroidField::AsteroidField(int n)
	{
		//Erzeuge Asteroiden-Vector der Groesse n
		m_field.resize(n);
		//Fuelle Vector mit Asteroiden
		std::generate(m_field.begin(),m_field.end(),randomAsteroid);
		
	}

	AsteroidField::~AsteroidField()
	{
		//Aufruf der Funktion deleteAsteroid fuer jeden Asteroiden
		std::for_each(m_field.begin(),m_field.end(),deleteAsteroid);
	}

	Asteroid* AsteroidField::randomAsteroid(void)
	{
		//Gibt Asteroiden zurueck mit zufaelligen Koordinaten und zufaelliger Skalierung unter Beruecksichtigung der uebergebenen Parameter
		return new Asteroid(TriangleMeshFactory::instance().getMesh("asteroid.3ds"),Randomizer::instance()->getRandomVertex(range),Randomizer::instance()->getRandomNumber(low,high));
  
		
	}

	void AsteroidField::deleteAsteroid(Asteroid* a)
	{
		//gibt Speicher des TriangleMesh des Asteroiden frei
		delete a;
	}

	void AsteroidField::renderAsteroid(Asteroid* a)
	{
		//Asteroid wird gerendert
		a->render();
	}

	void AsteroidField::render()
	{
		//Jeder Asteroid im Feld wird gerendert
		std::for_each(m_field.begin(),m_field.end(),AsteroidField::renderAsteroid);
	}
}
